/******************************************************************
 * Created by: DO HOANG HAI                                       
 * Date of Creation: 28/Aug/2007
 * Date of last modification: 2st/Sep/2007
 *                                                                
 * Description: Provide methods to access and manipulate the database.
 ******************************************************************/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Pbdms.DataAccess.DataProvider
{
    /// <summary>
    /// a Category provider provides services to read all categories available in the dabase
    /// </summary>
    public class CategoryProvider
    {
        public CategoryProvider()
        {
        }
        /// <summary>
        /// create an instance of the class
        /// </summary>
        /// <returns></returns>
        public static CategoryProvider create()
        {
            return new CategoryProvider();
        }

        /// <summary>
        /// get list of categories from the database.
        /// </summary>
        /// <returns></returns>
        public ArrayList getListOfCategories()
        {
            return XmlHelper.create("item.xml").selectMultipleElementValues("/root/Category/cat");
        }

        /// <summary>
        /// get category id with given category name
        /// </summary>
        /// <param name="sCatName"></param>
        /// <returns></returns>
        public String getCatIdByCatName(String sCatName)
        {
            ArrayList arl = XmlHelper.create("item.xml").selectMultipleAttributeValues("/root/Category/cat[contains (.,'" + sCatName + "')]", "id");
            if (arl != null)
                return arl[0].ToString();
            else
                return "";
        }

        /// <summary>
        /// get category name with given category id
        /// </summary>
        /// <param name="catId"></param>
        /// <returns></returns>
        public string getCatNameById(string catId)
        {
            return XmlHelper.create("item.xml").getInnerXML("/root/Category/cat[@id='"+ catId+"']");
        }
    }
}
